package watercups.operators;

import templates.Operator;
import watercups.states.WaterCupState;

public class Empty1to2 implements Operator<WaterCupState>{
	
	public int getOperatorNumber() {
        return 5;
    }

	public WaterCupState execute(WaterCupState s) {
		int ct = 4 - s.getCapacity2(); // cantitate ce trebuie transferata
		int ctrans; // cantitate transferata
		
    	if(ct < s.getCapacity1()) {
			ctrans = ct;
			s.setCapacity1(s.getCapacity1()-ctrans);
			s.setCapacity2(s.getCapacity2()+ctrans);
    		return new WaterCupState(s.getCapacity1(),s.getCapacity2());
			}
    	else {
			ctrans = s.getCapacity1();
			s.setCapacity1(s.getCapacity1()-ctrans);
			s.setCapacity2(s.getCapacity2()+ctrans);
    		return new WaterCupState(s.getCapacity1(),s.getCapacity2());
			}
    	
    }

    public String toString(){
        return "Emptying first cup into cup nr 2";
    }

	public boolean available(WaterCupState s) {
		if((s.getCapacity1()>0) && (s.getCapacity1()<=3) && (s.getCapacity2()<4))
			return true;
		return false;
	}
	
}
